package main.java.com.zyh;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class TestFile {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos3=new FileOutputStream("d:\\corejava\\3.txt");
        String sf = "d:\\corejava\\";
        String sb = ".txt";
        String sm1 = UUID.randomUUID().toString();
        String sm2 = UUID.randomUUID().toString();

        Map<String,String> map = new HashMap<>();
        map.put(sm1,sm2);
        map.forEach((key,value)->{
            copy1("d:\\哈哈.jpg",key,value);
            try {
                fos3.write(key.getBytes());
                fos3.write("\n".getBytes());
                fos3.write(value.getBytes());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        map.forEach((key,value)->{
            copy2(key,value,"d:\\corejava\\3.jpg");
        });
        //copy2();
    }
    public static void copy1(String inPath, String outPath1, String outPath2) {
        try(
                FileInputStream fis=new FileInputStream(inPath);
                FileOutputStream fos=new FileOutputStream("d:\\corejava\\"+outPath1+".txt");
                FileOutputStream fos2=new FileOutputStream("d:\\corejava\\"+outPath2+".txt");
        ){
            while(true){
                byte[] b=new byte[1024];
                byte[] c=new byte[1024];
                int n = fis.read(b);
                int m = fis.read(c);
                System.out.println(n);
                if(n==-1 || m==-1){
                    System.out.println("文件读取结束！");
                    break;
                }

                fos.write(b);
                fos2.write(c);
            }
            System.out.println("复制完成！");
        } catch (Exception e) {
            System.out.println("运行异常!");
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    public static void copy2(String inPath1, String inPath2, String outPath) {
        try(
                FileInputStream fis=new FileInputStream("d:\\corejava\\"+inPath1+".txt");
                FileInputStream fis2=new FileInputStream("d:\\corejava\\"+inPath2+".txt");
                FileOutputStream fos=new FileOutputStream(outPath);
                ){
                while(true){
                    byte[] b=new byte[1024];
                    byte[] c=new byte[1024];
                    int n = fis.read(b);
                    int m = fis2.read(c);
                    System.out.println(n);
                    if(n==-1 || m==-1){
                        System.out.println("文件读取结束！");
                        break;
                    }

                    fos.write(b);
                    fos.write(c);
                }
                System.out.println("复制完成！");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
